﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;

public class tbDepartmentsDB
{
    #region[tbDepartments_Add]
    public static bool tbDepartments_Add(tbDepartmentsDATA _tbDepartmentsDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbDepartments_Add", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@dpCode", _tbDepartmentsDATA.dpCode));
                dbCmd.Parameters.Add(new SqlParameter("@dpName", _tbDepartmentsDATA.dpName));
                dbCmd.Parameters.Add(new SqlParameter("@dpLevel", _tbDepartmentsDATA.dpLevel));
                dbCmd.Parameters.Add(new SqlParameter("@dpOrd", _tbDepartmentsDATA.dpOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbDepartments_Update]
    public static bool tbDepartments_Update(tbDepartmentsDATA _tbDepartmentsDATA)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbDepartments_Update", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@dpID", _tbDepartmentsDATA.dpID));
                dbCmd.Parameters.Add(new SqlParameter("@dpCode", _tbDepartmentsDATA.dpCode));
                dbCmd.Parameters.Add(new SqlParameter("@dpName", _tbDepartmentsDATA.dpName));
                dbCmd.Parameters.Add(new SqlParameter("@dpLevel", _tbDepartmentsDATA.dpLevel));
                dbCmd.Parameters.Add(new SqlParameter("@dpOrd", _tbDepartmentsDATA.dpOrd));
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbUser_Delete]
    public static bool tbDepartments_Delete(string dpID)
    {
        bool check = false;
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbDepartments_Delete", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@dpID", dpID));
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
                dbConn.Close();
                check = true;
            }
        }
        return check;
    }
    #endregion
    #region[tbDepartments_GetByAll]
    public static List<tbDepartmentsDATA> tbDepartments_GetByAll()
    {
        List<tbDepartmentsDATA> list = new List<tbDepartmentsDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbDepartments_GetByAll", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbDepartmentsDATA objtbDepartmentsDATA = new tbDepartmentsDATA(
                        reader["dpID"].ToString(),
                        reader["dpCode"].ToString(),
                        reader["dpName"].ToString(),
                        reader["dpLevel"].ToString(),
                        reader["dpOrd"].ToString());
                        list.Add(objtbDepartmentsDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
    #region[tbDepartments_GetByID]
    public static List<tbDepartmentsDATA> tbDepartments_GetByID(string dpID)
    {
        List<tbDepartmentsDATA> list = new List<tbDepartmentsDATA>();
        using (SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_tbDepartments_GetByID", dbConn))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbConn.Open();
                dbCmd.Parameters.Add(new SqlParameter("@dpID", dpID));
                using (SqlDataReader reader = dbCmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        tbDepartmentsDATA objtbDepartmentsDATA = new tbDepartmentsDATA(
                        reader["dpID"].ToString(),
                        reader["dpCode"].ToString(),
                        reader["dpName"].ToString(),
                        reader["dpLevel"].ToString(),
                        reader["dpOrd"].ToString());
                        list.Add(objtbDepartmentsDATA);
                    }
                }
                dbConn.Close();
            }
        }
        return list;
    }
    #endregion
}